package com.abe.abetest;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;

import com.abe.abetest.alarm.AlarmHelper;
import com.abe.libbase.base.BaseActivity;

public class OpenOtherAppActivity extends BaseActivity {
    @Override
    public int getLayoutRes() {
        return R.layout.activity_open_other_app;
    }

    @Override
    public void init() {
        findViewById(R.id.item_btn).setOnClickListener(view -> runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                        gotoEnterpriseArchives("Http://172.16.6.13:8406/MobileWCFREST/", "", false,
//                                "370300", "370300", "淄博市", "淄博市");
                //http://192.168.163.2:8401/MBWCF/
//                        EnterpriseHelper.init("Http://172.16.6.13:8406/MobileWCFREST/", "", false,
//                                "370300", "370300", "淄博市", "淄博市");
//                EnterpriseHelper.init("http://192.168.163.2:8401/MBWCF/", "", true,
//                        "370300", "370300", "淄博市", "淄博市");
                //跳转至一厂一档
                //EnterpriseHelper.openDetail(OpenOtherAppActivity.this, "370300000000201600072", "淄博市利民净化水有限公司");
                AlarmHelper.setAlarm(OpenOtherAppActivity.this, 1000, 10, 5, 5, "123", "{data:234}");
            }
        }));
        findViewById(R.id.item_btn_cancel).setOnClickListener(view -> runOnUiThread(new Runnable() {
            @Override
            public void run() {
                AlarmHelper.deleteAlarm(OpenOtherAppActivity.this, 1000);
            }
        }));
    }

    /**
     * 惯例是ssqydm与servercode是相同的，servername与cityname是相同的
     *
     * @param mobileUrl       移动执法手机服务地址
     * @param wryDetailWebUrl 移动执法污染源台账地址，暂时填空字符串
     * @param isCanUpdate     是否能更新企业信息，暂时填flase
     * @param ssqydm          所属区域代码
     * @param servercode      所属服务器代码
     * @param servername      所属服务器名称
     * @param cityname        所属城市名称
     */
    private void gotoEnterpriseArchives(String mobileUrl, String wryDetailWebUrl, boolean isCanUpdate,
                                        String ssqydm, String servercode, String servername, String cityname) {
        Bundle bundle = new Bundle();
        bundle.putString("mobileUrl", mobileUrl);
        bundle.putString("wryDetailWebUrl", wryDetailWebUrl);
        bundle.putBoolean("isWryNeedUpdate", isCanUpdate);
        bundle.putString("ssqydm", ssqydm);
        bundle.putString("servercode", servercode);
        bundle.putString("servername", servername);
        bundle.putString("cityname", cityname);
        Intent intent = new Intent();
        ComponentName cn = new ComponentName("com.golden3c.emles",
                "com.golden3c.emles.mb.enterprise.GuideActivity");
        intent.setComponent(cn);
        intent.setData(Uri.parse("enterprise_archives"));
        intent.putExtras(bundle);
        try {
            startActivity(intent);
        } catch (Exception e) {
            //TODO 未安装提示
            Toast.makeText(OpenOtherAppActivity.this, "没有该子APP，请下载安装", Toast.LENGTH_SHORT).show();
        }
    }
}